import javax.swing.* ;
import java.io.* ;
import java.net.* ;

public class SocketReadThread extends Thread {

   Socket sk = null ;
   JTextArea ta = null ;
   
   public SocketReadThread ( Socket s, JTextArea a) { sk = s;  ta = a ; } 

   public void run() {
	try {
		BufferedReader in = new BufferedReader ( new InputStreamReader(sk.getInputStream())) ;
		String s = null;
		s = in.readLine() ;
		while ( s != null && ! s.equals("END") ) {
			s = "Data " + s + " sent from " + sk.getInetAddress().getHostName() +
					  " to  " + sk.getInetAddress().getLocalHost().getHostName() ;
			ta.append(s + "\n");
			if ( ta.getText().length() > 0 ) ta.setCaretPosition(  ta.getText().length()  - 1) ;

			Thread.yield() ;  // give up CPU
			// sleep(500);
			s = in.readLine() ;
		}
 	} catch( IOException e ) { e.printStackTrace() ; }
 	 // catch( InterruptedException ie ) { ie.printStackTrace() ; }
   }
}
